<!--
 * @Author: Dorange.Wang
 * @Date: 2021-07-09 15:15:38
 * @LastEditors: your name
 * @LastEditTime: 2021-07-20 15:37:32
 * @Description: file content
-->
<template>
  <van-field
    readonly
    clickable
    :label="instance.__config.label"
    :value="value"
    :placeholder="instance.__config.placeholder"
    @click="handleClick"
  />
</template>

<script>
import { widgetMixin } from "../mixin";
import { postHmhttprequestdefinitionExecute } from "@/apis/app/HmHttpRequestDefinitionController";
import Select from "@/components/select/instance";
export default {
  name: "HanSelect",
  mixins: [widgetMixin],
  data() {
    return {
      value: "",
      listData: {},
    };
  },

  created() {
    this.init();
  },

  methods: {
    async init() {
      const listData = await this.getListData();
      this.listData = listData;
    },

    async getListData({ keyword = "", pageNo = 1, pageSize = 20 } = {}) {
      const {
        modelKey,
        modelCode,
        relationType,
        valueTeam,
      } = this.instance.__config;
      const listData = await postHmhttprequestdefinitionExecute({
        key: "selectByPage",
        modelKey,
        pageNo,
        pageSize,
        values: {
          keyword,
          modelCode,
          relationType,
          value: valueTeam,
        },
      });
      return listData;
    },

    handleClick() {
      const { multiple } = this.instance.__config;
      Select.init({
        listData: this.listData,
        multiple,
        onSearch: async (params = {}) => {
          const { keyword, pageNo } = params;
          const data = await this.getListData({ keyword, pageNo });
          return data;
        },
        onConfirm: () => {},
        onCancel: () => {},
      });
    },
  },
};
</script>

<style></style>
